<template>
    <div>

        <el-breadcrumb class="breadcrumb" separator="/">
            <transition-group name="breadcrumb">
                <el-breadcrumb-item v-for="(item, index) in breadcrumbData" :key="item.path">
                    <!-- 不可以点击项 -->
                    <span v-if="index === breadcrumbData.length - 1" class="no-redirect">{{ item.meta.title }}</span>
                    <!-- 可以点击项 -->
                    <a v-else class="redirect" @click.prevent="onLinkClick()">{{
                        item.meta.title
                    }}</a>
                </el-breadcrumb-item>
            </transition-group>
        </el-breadcrumb>

    </div>
</template>
  
<script setup>
import { ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { isCollapseStore } from '../../stores/user'

const CollapseStore = isCollapseStore();
const route = useRoute();
const router = useRouter();
// 生成数组数据
const breadcrumbData = ref([]);
const getBreadcrumbData = () => {
    console.log(route.matched);
    breadcrumbData.value = route.matched
};
// 监听路由发生改变时触发
watch(
    route,
    () => {
        getBreadcrumbData();
    },
    {
        immediate: true,
    }
);
const onLinkClick = () => {
    router.push('/home');
};
const retract = () => {
    CollapseStore.updata()
}
</script>
  
  
<style>
.Bread {
    height: 30px;
    float: left;
}

.breadcrumb-enter-active,
.breadcrumb-leave-active {
    transition: all 0.5s;
}

.breadcrumb-enter-from,
.breadcrumb-leave-active {
    opacity: 0;
    transform: translateX(20px);
}

.breadcrumb-leave-active {
    position: absolute;
}

.breadcrumb {
    display: flex;
    font-size: 14px;
    line-height: 50px;
    margin-left: 8px;

    .no-redirect {
        color: rgb(250, 200, 80);
        cursor: text;
        font-size: 20;
    }

    .redirect {
        color: rgb(250, 200, 80);
        font-weight: 600;
        font-size: 20;
    }

}
</style>